/*******************************************************************************
 * Project Key : AUTHCENTER 
 * Create on 2015-4-29 下午2:53:47
 * Copyright (c) 2004 - 2015. 拉卡拉支付有限公司版权所有. 京ICP备12007612号
 * 注意：本内容仅限于拉卡拉支付有限公司内部传阅，禁止外泄以及用于其他的商业目的
 ******************************************************************************/
package cn.touna.jss.modules.third.zhima.client;

import cn.touna.jss.common.properties.disconf.ZhimaProperties;
import com.alibaba.fastjson.JSON;
import com.antgroup.zmxy.openplatform.api.DefaultZhimaClient;
import com.antgroup.zmxy.openplatform.api.request.ZhimaCreditScoreGetRequest;
import com.antgroup.zmxy.openplatform.api.response.ZhimaCreditScoreGetResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <P>获取芝麻评分客户端</P>
 *
 * @author tianhuaxing 2017年5月22日 下午8:02:23
 * @since 1.0.0.000
 */
@Component
public class ScoreGetClient {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ZhimaProperties zhimaProperties;

    /**
     * 获取芝麻分
     */
    public ZhimaCreditScoreGetResponse zhimaCreditWatchlistGet(String openId, String sid) throws Exception {
        ZhimaCreditScoreGetRequest req = new ZhimaCreditScoreGetRequest();
        ZhimaCreditScoreGetResponse response = null;
        req.setProductCode(zhimaProperties.getProductCode());// 必要参数
        req.setOpenId(openId);// 必要参数
        req.setTransactionId(sid);// 必要参数
        DefaultZhimaClient client = new DefaultZhimaClient(zhimaProperties.getGatewayUrl(), zhimaProperties.getAppId(),
                zhimaProperties.getPrivateKey(), zhimaProperties.getZhimaPublicKey());
        response = client.execute(req);
        logger.info("【调用芝麻评分】芝麻评分结果:{}", JSON.toJSON(response));
        return response;
    }

    public String getProductCode() {
        return zhimaProperties.getProductCode();
    }

    public void setProductCode(String productCode) {
        this.zhimaProperties.setProductCode(productCode);
    }

}